<template>
  <div class="home">
    <Nav :title="title"></Nav>
    <div class="position" @click="toCity">
      {{position}}
      <i class="iconfont icon-xiasanjiao"></i>
    </div>
    <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
      <van-swipe-item>
        <img src="../images/nav/nav1.jpg" alt />
      </van-swipe-item>
      <van-swipe-item>
        <img src="../images/nav/nav2.jpg" alt />
      </van-swipe-item>
    </van-swipe>
    <van-tabs @click="onClick">
      <van-tab title="正在热映"></van-tab>
      <van-tab title="即将上映"></van-tab>
    </van-tabs>
    <router-view></router-view>
  </div>
</template>

<script>
import Nav from "../components/Nav";
import fade from "../components/Fade";
export default {
  name: "Home",
  data() {
    return {
      position: "",
      title: "电影"
    };
  },
  components: {
    Nav,
    fade
  },
  mounted() {
    this.position = localStorage.getItem("city");
    this.$router.push({ path: "/home/nowPlaying" });
  },
  methods: {
    onClick(name) {
      console.log(name);
      if (name == 0) {
        this.$router.push({ path: "nowplaying" });
      } else if (name == 1) {
        this.$router.push({ path: "comingsoon" });
      }
    },
    // 转到城市
    toCity() {
      this.$store.commit("setState", false);
      setTimeout(() => {
        this.$router.push({ name: "city" });
        this.$store.commit("setState", true);
      }, 500);
    }
  }
};
</script>
<style scoped>
.position {
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 10;
  background-color: rgba(0.5, 0.5, 0.5, 0.3);
  padding: 5px;
  border-radius: 16px;
  color: white;
}
img {
  width: 100%;
}
</style>